﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using DigitalRune.Windows.TextEditor;
using EmbeddedSharp.Core;

namespace Zove.Desktop {
    public partial class BreakpointView : DockContent {
        public BreakpointView() {
            InitializeComponent();

            this.Load += new EventHandler(BreakpointView_Load);
        }

        public void BreakpointView_Load(object sender, EventArgs e) {
            this.dataGridView1.DataSource = DesktopFormContext.Context.BreakPoints;
        }

        private void toggleBreakpointToolStripMenuItem_Click(object sender, EventArgs e) {
            ProgrammingEditor pe = ((ProgrammingEditor)
                ((Form1)DesktopFormContext.Context.Main).ActiveMdiChild);
            TextEditorControl tec = pe.GetTextEditorControl();

            int line = tec.ActiveTextAreaControl.Caret.Line;

            BreakPoint bp = new BreakPoint();
            bp.File = pe.FileName;
            bp.LineNumber = line;
            bp.Condition = "";
            bp.Enabled = false;

            foreach (BreakPoint b in DesktopFormContext.Context.BreakPoints) {
                if (bp.LineNumber == b.LineNumber && bp.File == b.File) {
                    return;
                }
            }

            DesktopFormContext.Context.BreakPoints.Add(bp);

            this.dataGridView1.DataSource = DesktopFormContext.Context.BreakPoints;
        }

        private void setupBreakpointToolStripMenuItem_Click(object sender, EventArgs e) {

        }

        private void itemDeleteBreakPoint_Click(object sender, EventArgs e) {
            if (this.dataGridView1.SelectedCells.Count == 0) {
                return;
            }

            this.dataGridView1.Rows.RemoveAt(
                this.dataGridView1.SelectedCells[0].RowIndex);
        }
    }
}
